<?php
namespace views;

define('VIEW_PATH','./views/');
define('HEADER','./views/header.php');
define('FOOTER','./views/footer.php');
/**
 * 视图渲染类
 */
class View
{
    protected $_view;

    protected $params = array();

    protected $title;

    /**
     * 构造函数，传递参数视图文件
     */
    public function __construct($title, $view)
    {
        $this->title = $title;
        $this->_view = VIEW_PATH . $view;
    }

    /**
     * 渲染视图
     */
    public function render($data=[])
    {
        extract($data);
        
        // 页头文件
        if (is_file(HEADER)) {
            include (HEADER);
        }

        //判断视图文件是否存在
        if (is_file($this->_view)) {
            include ($this->_view);
        } else {
            echo "<h1>无法找到视图文件</h1>";
        }
        
        // 页脚文件
        if (is_file(FOOTER)) {
            include (FOOTER);
        }
    }
}